const express = require("express");
const bodyParser = require("body-parser");
const { person } = require("./modules/person");
const { register} = require("./modules/register");
const { login } = require("./modules/login");
const { getEmail }= require("./modules/getEmail");
const session = require("express-session");




const app = express();

// 注册body-parser中间件：在路由功能内，可以使用req.body解析post数据
app.use(bodyParser.urlencoded({ extended: false }));

app.use(express.static("./www"));
// app.use(express.static("./upload"));

app.use(express.urlencoded({extended: false}));

app.all("*",(req,res,next)=>{
    res.header('Access-Control-Allow-Origin', '*')
    res.header('Access-Control-Allow-Methods', 'get,post')
    res.header('Access-Control-Allow-Headers', 'Content-Type')
    next();
})
app.use(session({
    secret: 'panmy',   // 加密信息，可以随便写
    resave: false,     // 强制保存session，默认为true，建议设置为false
    saveUninitialized: true,   // 强制将未初始化的session存储，默认为true，建议为true
    cookie: { maxAge: 1000 * 60 * 30 }    // 过期时间，毫秒数
}))

app.get("/person", person() );

app.post("/register", register() );
app.get("/login", login() );



app.get("/getEmail",getEmail());




app.listen(3000, ()=>{
    console.log("服务器开启成功,地址为: http://localhost:3000")
})
